<template>
	<view class="main">
		<u--form
			labelPosition="left"
			ref="form1">
			<view class="form">
				<textarea v-model="formData.content" placeholder="请输入举报内容信息"></textarea>
			</view>
			<view class="form">
				<view class="imageUpload">
					<view>上传图片</view>
					<view>请上传违规内容截图</view>
				</view>
				<u-upload
					:fileList="fileList1"
					@afterRead="afterRead"
					@delete="deletePic"
					name="1"
					multiple
					:maxCount="1"
					:previewFullImage="true"
				></u-upload>
			</view>
		</u--form>
			
		
		<view class="submit"><u-button type="primary" @click="sendPost()" text="提交"></u-button></view>
		<u-datetime-picker
			:show="dateShow"
			v-model="dateVal"
			:minDate='0'
			:maxDate="maxDate"
			mode="date"
			@confirm="dateConfirm"
			@cancel="dateCancel"
			></u-datetime-picker>
		
	</view>
</template>

<script>
import Index from '@/common/index-model.js'
import pop from "@/components/ming-pop/ming-map.vue"
import fun from "@/common/publicFun.js"
let index=new Index();
let that = null;
export default {
	data() {
		return {
			id:'',
			myCard:{},
			formData:{
				content:'',
				imgUrl:'',
				issueDate:''
			},
			maxDate:'',
			dateShow:false,
			dateVal:'',
			fileList1: [],
			fileImgUrl:[],//图片
			targetId:'',
			type:-1
		}
	},
	onLoad(opt) {
		this.targetId=opt.targetId;
		this.type = opt.type
	},
	onShow() {
		
	},
	components: {
		pop
	},
	methods:{
		sendPost(){
			if(!this.formData.content){
				index.show_tips('请输入举报内容')
				return
			}
			let data = {
				type:this.type,
				targetId:this.targetId,
				pic:this.formData.imgUrl,
				content:this.formData.content
			}
			console.log('举报内容',data)
			index.getPublicUserMember(data,"/client/impeach/addImpeach",'post',res=>{
				if(res.data.code == 200 && res.data.success){
					index.show_tips('举报成功')
					setTimeout(()=>{
						index.navigate_back(1)
					},2000)
				}else{
					index.show_tips(res.data.message);
					return false
				}
			})
			
		},
		// 删除图片
		deletePic(event) {
			this[`fileList${event.name}`].splice(event.index, 1)
			this.fileImgUrl.splice(event.index, 1)
		},
		// 新增图片
		async afterRead(event) {
			// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
			let lists = [].concat(event.file)
			let fileListLen = this[`fileList${event.name}`].length
			lists.map((item) => {
				this[`fileList${event.name}`].push({
					...item,
					status: 'uploading',
					message: '上传中'
				})
			})
			for (let i = 0; i < lists.length; i++) {
				const result = await this.uploadFilePromise(lists[i].url)
				let item = this[`fileList${event.name}`][fileListLen]
				this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
					status: 'success',
					message: '',
					url: result
				}))
				fileListLen++
			}
		},
		uploadFilePromise(url) {
			return new Promise((resolve, reject) => {
				let a = uni.uploadFile({
					url: index.img_url+'client/public/upload?type=headPicture&file='+url, // 仅为示例，非真实的接口地址
					filePath: url,
					name: 'file',
					formData: {
						user: 'test'
					},
					header: {
						'X-Access-Token':uni.getStorageSync('token'),
						'Login-Type':'client'
					},
					success: (res) => {
						this.formData.imgUrl=JSON.parse(res.data).result.url;
						this.fileImgUrl.push({'url':JSON.parse(res.data).result.url})
						setTimeout(() => {
							resolve(res.data.data)
						}, 1000)
					}
				});
			})
		},
	}
}	
</script>

<style>
@import url("@/static/css/publics.css");
@import url("../../pagesB/perfectWork/findJob.css");
page{
	background: #F3F3F3;
}
.forms{ padding: 20rpx; background: #fff; margin-bottom: 20rpx;}
.form{ padding: 20rpx; background: #fff; margin-bottom: 20rpx;}
.imageUpload view:nth-child(1){ color: #3D3D3D;}
.imageUpload view:nth-child(2){ color: #A1A1A1; font-size: 24rpx; margin-bottom: 20rpx; margin-top: 8rpx;}
.submit{ padding: 20rpx;height: 35px;}
/deep/.input-placeholder{ color: #f00;}


</style>